#include <stdio.h>
#include <string.h>

// i am from nanjing
// nanjing from am i

//字符串逆序
void Reserve(char *s, int len)
{
    for(int i = 0; i < len / 2; i++)
    {
        char temp = s[i];
        s[i] = s[len - 1 - i];
        s[len - 1 - i] = temp;
    }
}

//字符逆序
void Reserve2(char *s, int len)
{
    //记字符串长度
    int count = 0;
    for(int i = 0; i <= len; i++)
    {
        //一个单词结束了
        if(s[i] == ' ' || s[i] == '\0')
        {
            //一个单词逆序了
            Reserve(s+i-count, count);
            //开始统计下一个单词
            count = 0;
        }
        else
        {
            count++;
        }
    }
}

int main()
{
    char s[] = "i am from nanjing";
    Reserve(s, strlen(s));
    Reserve2(s, strlen(s));
    printf("%s\n", s);

    return 0;
}